public class RoutingPlanChangeOwner_TestClass
{
    static testmethod void test()
    {
        Profile pTsr = [select id from profile where  name = 'Sales Rep - Trade' limit 1];
        Profile pASM = [select id from profile where  name = 'Area/District Sales Manager - Medical' limit 1];
        Profile pDSM = [select id from profile where  name = 'Area/District Sales Manager - Medical' limit 1];
        Profile pAdmain=[select id from profile where name='System Administrator'];
        
        //UserRole role1 = new UserRole (name='role1');
        //insert role1;
        //UserRole role2 = new UserRole(name='role2', ParentRoleId=role1.id);
        //insert role2;
        UserRole role1 = [Select Id From UserRole Where name =: 'SOC1 GuangZhou ASM/DSM-T1'];
        UserRole role2 = [Select Id From UserRole Where name =: 'SOC1 GuangZhou Sales Supervisor-T1a'];
        
        User uASM = new User(alias='standtss', email='sdudfdr@testorgss.com',
        emailencodingkey='UTF-8', lastname='Testeing', languagelocalekey='en_US',
        localesidkey='en_US', profileid=pASM.Id,IsActive=true, UserRoleId=role1.id,
        Title__c='Area/District Sales Manager',FunctionDepartment__c='Trade Sales',
        timezonesidkey='America/Los_Angeles', username='stsdfdfrs@testorg.com');
        insert uASM;
        
        User uDSM = new User(alias='standtss',email='sdusdfer@testorgss.com',ManagerId=uASM.Id,emailencodingkey='UTF-8', lastname='Testeing',
        languagelocalekey='en_US',localesidkey='en_US',timezonesidkey='America/Los_Angeles',profileid=pDSM.Id,
        Title__c='Area/District Sales Manager',FunctionDepartment__c='Trade Sales',
        username='stserers@testorg.com');
        insert uDSM;
        
        User uTsr = new User(alias='standtss',email='sduser@testorgss.com',emailencodingkey='UTF-8',ManagerId=uDSM.Id, lastname='Testeing',
        languagelocalekey='en_US',localesidkey='en_US',timezonesidkey='America/Los_Angeles',profileid=pTsr.Id,
        Title__c='Sales Rep',FunctionDepartment__c='Trade Sales',UserRoleId=role2.id,
         username='stsers@testorg.com');
        insert uTsr;
        
        User uTsr2 = new User(alias='standtss', email='sdusfsdfer@testorgss.com',
        emailencodingkey='UTF-8', lastname='Testeing', languagelocalekey='en_US',
        localesidkey='en_US', profileid=pTsr.Id,IsActive=true,UserRoleId=role2.id,
        Title__c='Sales Rep',FunctionDepartment__c='Trade Sales',ManagerId=uDSM.Id,
        timezonesidkey='America/Los_Angeles', username='stssfds@testorg.com');
        insert uTsr2;
        
        System.runAs(uTsr)
        {
            Routing_Plan_And_Visit__c r=new Routing_Plan_And_Visit__c(Visit_Date__c=System.today().addMonths(1),OwnerId=uTsr.Id);
            insert r;
        }
        
         System.runAs(uASM)
        {
            List<Routing_Plan_And_Visit__c> r=[select Id,Visit_Date__c,OwnerId from Routing_Plan_And_Visit__c];
            if (r.size() > 0)
            {
                r[0].OwnerId=uTsr2.Id;
                //r[0].Visit_Date__c=Date.valueOf(r[0].Visit_Date__c).addDays(1);
                update r;
            }
        }
    }
}